package com.yonyou.pmclouds.measureindex.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.measureindex.entity.MeasureIndexVO;
import com.yonyou.pmclouds.plan.planindex.entity.PlanIndexVO;
import com.yonyou.pmclouds.plan.planindex.mapper.PlanIndexMapper;

import java.util.HashSet;

public class CheckMeasureIndexRefProcessor implements SingleProcessor<MeasureIndexVO> {
    private PlanIndexMapper mapper;

    public CheckMeasureIndexRefProcessor(PlanIndexMapper mapper){
        this.mapper = mapper;
    }

    @Override
    public void process(MeasureIndexVO vo, MeasureIndexVO orig) throws BusinessException {
        String pkMeasureindex = vo.getPkMeasureindex();
        if(pkMeasureindex == null) return;
        HashSet<String> pkMeasureindexs = new HashSet<>();
        pkMeasureindexs.add(pkMeasureindex);
        PlanIndexVO[] planIndexVOS = mapper.queryIdnexByPkMeasureindex(pkMeasureindexs);
        if(planIndexVOS != null && planIndexVOS.length != 0 ) throw new BusinessException("指标'"+orig.getName()+"'被引用无法删除");
    }
}
